package com.alog.yzd.bookmall.utils;

import javax.servlet.http.HttpServletRequest;

public class WebUtils {

    /**
     * 截取URL, 页面中的分页导航要使用它作为超链接的目标
     * @param request
     * @return
     */
    public static String getUri(HttpServletRequest request){
        String url = request.getRequestURI(); //"/goods/BookServlet"
        String queryStr = request.getQueryString();//"method=..."
        //如果参数中存在Pc参数, 截取掉
        int index = queryStr.lastIndexOf("&pc=");
        if(index != -1){
            queryStr = queryStr.substring(0,index);
        }
        return url + "?" + queryStr;
    }
    /**
     * 获取当前页
     * @param request
     * @return
     */
    public static int getPc(HttpServletRequest request){
        int pc = 1 ;
        String param = request.getParameter("pc");
        if(param != null && !param.trim().isEmpty()){
            try{
                pc = Integer.valueOf(param);
            } catch (Exception e){
                e.printStackTrace();
            }
        }
        return pc;
    }
}
